package com.wanyu.video.nio.channel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * 使用NIO的channel To channel方法copy文件
 */
public class NIOFileCopyChannelToChannel {


    public static void main(String[] args) throws IOException {

        FileInputStream inputStream = new FileInputStream("C:\\git_code\\netty-in-action-learn\\file\\source.png");
        FileChannel source = inputStream.getChannel();

        FileOutputStream outputStream = new FileOutputStream("C:\\git_code\\netty-in-action-learn\\file\\source-copy.png");
        FileChannel dest = outputStream.getChannel();


        dest.transferFrom(source, 0, source.size());

        source.close();
        dest.close();
        inputStream.close();
        outputStream.close();
    }
}
